package com.ziJing.multithreading.sync.t_03_ThreadPool;

import java.util.concurrent.*;

/**
 * @program Multithreading
 * @description:
 * @author: zhangbo
 * @create: 2022/05/09 22:54
 */
public class T02_MyRejectedHandler {

    public static void main(String[] args) {
        new ThreadPoolExecutor(
                4,
                4,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy());
    }

    static class MyHandler implements RejectedExecutionHandler{

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            //log.info("r rejected")
            //save r kafka mysql redis
            //try 3 times
            if(executor.getQueue().size() < 10000){
                //try put again();
            }
        }
    }
}
